package com.nixsolutions.service;

import com.nixsolutions.bean.Role;
import com.nixsolutions.dao.RoleDao;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author yakimovich
 */
public class RoleServiceImpl implements RoleService {

    private static org.apache.commons.logging.Log logger = LogFactory.getLog(RoleServiceImpl.class);
    
    @Qualifier("roleDao")
    @Autowired
    private RoleDao roleDao;

    public RoleDao getRoleDao() {
        return roleDao;
    }

    public void setRoleDao(RoleDao roleDao) {
        this.roleDao = roleDao;
    }

    @Override
    @Transactional
    public void create(Role role) {

        try {
            roleDao.create(role);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public void update(Role role) {

        try {
            roleDao.update(role);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public void remove(Role role) {

        try {
            roleDao.remove(role);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }

    @Override
    @Transactional
    public Role findByName(String name) {

        try {
            return  roleDao.findByName(name);
        } catch (Exception e) {
            logger.error(this, e);
            throw new RuntimeException(e);
        }
    }
}

